package com.k.kpp.service;

import com.k.kpp.dao.CommonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CommonServiceImpl implements CommonService {
    @Autowired
    private CommonMapper commonMapper;
    @Override
    public List<Map<String, Object>> executeSql(String sql) {
        return commonMapper.executeSql(sql);
    }

    @Override
    public List<Map<String, Object>> selectList(Map<String, Object> map) {
        return commonMapper.selectList(map);
    }

    @Override
    public Map<Integer, Map<Integer, String>> getDataFromExcelFile(MultipartFile zipFile, int sheetCount) {
        String dir = "/usr/CommandCenter/CDSS/server/conf/";
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {
            dir = "c:/";
        }
        String fileName = dir + System.currentTimeMillis() + "_" + zipFile.getOriginalFilename();
        Map<Integer, Map<Integer, String>> map = new HashMap<>();
        File file = new File(fileName);
        try {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdir();
            }
            zipFile.transferTo(file);
            map = null;//ExcelUtils.readExcelToMap(file.getAbsolutePath(),sheetCount);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            file.delete();
        }
        return map;
    }
}
